package cn.tedu.attendance.service.impl;

import cn.tedu.attendance.mapper.AttendanceMapper;
import cn.tedu.attendance.pojo.dto.AttendanceQuery;
import cn.tedu.attendance.pojo.vo.AttendanceVO;
import cn.tedu.attendance.service.AttendanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class AttendanceServiceImpl implements AttendanceService {
    @Autowired
    private AttendanceMapper attendanceMapper;
    @Override
    public List<Map> select(AttendanceQuery attendanceQuery) {
        log.debug("开始处理【查询考勤记录】的请求业务，参数：{}", attendanceQuery);
        List<AttendanceVO> selectList = attendanceMapper.select(attendanceQuery);
        List<Integer> normalList = new ArrayList<>();
        List<Integer> beLateList = new ArrayList<>();
        List<Integer> leaveEarlyList = new ArrayList<>();
        List<Integer> vacateList = new ArrayList<>();
        List<Integer> lackOfCardList = new ArrayList<>();
        List<Integer> absenteeismList = new ArrayList<>();

        for (AttendanceVO attendanceVO : selectList) {
            if (attendanceVO.getStatus().equals("1")) {
                normalList.add(1);
            } else if (attendanceVO.getStatus().equals("2")) {
                beLateList.add(2);
            } else if (attendanceVO.getStatus().equals("3")) {
                leaveEarlyList.add(3);
            } else if (attendanceVO.getStatus().equals("4")) {
                vacateList.add(4);
            } else if (attendanceVO.getStatus().equals("5")) {
                lackOfCardList.add(5);
            } else if (attendanceVO.getStatus().equals("6")) {
                absenteeismList.add(6);
            }
        }

        Map<String, Integer> statMap = new HashMap<>();
        statMap.put("normal", normalList.size());
        statMap.put("beLate", beLateList.size());
        statMap.put("leaveEarly", leaveEarlyList.size());
        statMap.put("vacate", vacateList.size());
        statMap.put("lackOfCard", absenteeismList.size());
        statMap.put("absenteeism", lackOfCardList.size());

        List<Map> stasList = new ArrayList<>();
        stasList.add(statMap);

        return stasList;
    }
}